##################################################################
# File : lua/sim/Attacker.lua
# Description : Attacker lua module
# Author : GPG
##################################################################

ATTACKEVENT = {
    # We have no target set
    NoTarget = 0,

    # Acquired specifically the attacker's desired target
    AcquiredDesiredTarget = 1,

    # Desired target is out of range (too far)
    OutOfRange = 2,

    # Desired target is too close or on the wrong layer
    Unreachable = 3,

    # Desired target was destroyed
    Success = 4,

    # Abondon the Desired target (like target going out of guard range)
    GiveUp = 5,

    # Current firing position is not good, so relocate to a better spot
    Relocate = 6,

    # You're too close to the target. Gain some distance between you and the target
    TooClose = 7,

    # Force end of attack task
    ForceEndAttack = 8,

    # Force to engage this target because I'm being engaged by it.
    ForceEngage = 9,

    # New target acquired, update AttackTask
    NewTargetAcquired = 10,

    str = function(self,v) return table.find(self,v) end
}

TARGETTYPE = {
    None = 0,
    Entity = 1,
    Ground = 2,

    str = function(self,v) return table.find(self,v) end
}

ENEMYSEARCH = {
    Closest = 0,
    LeastDeflection = 1,

    str = function(self,v) return table.find(self,v) end
}

Attacker = Class(moho.attacker_methods) {

    # NATIVE METHODS
    --[[

    # Returns the unit this attacker is bound to.
    unit GetUnit()

    # Returns if the attacker has any weapon that is currently attacking any enemies
    bool WeaponsBusy()

    # Return the count of weapons.
    int GetWeaponCount()

    # Force the unit to set the given unit as its enemy. AI takes
    # care of how to attack the enemy if possible. Each of our
    # weapons has its own target, and the AI will do its best to set
    # those targets to our specified enemy, but if the weapon is
    # unable to fire upon this enemy it will continue searching for
    # other things it can attack. If it engages another enemy it
    # will continually attempt to acquire the desired target.
    nil SetDesiredTarget(AITarget)
    AITarget GetDesiredTarget()

    # Stop will cease all firing upon enemies or ground
    # positions.  However the weapons can still pick up enemies and
    # begin firing on their own. Same as SetDesiredTarget(nil)
    Stop()

    # Loop through the weapons to see if the target can be attacked
    bool CanAttackTarget(AITarget)

    # Find the best enemy target for a weapon
    entity FindBestEnemy(weapon,range,enemysearchType)

    # Loop through the weapons to find one that we can use to attack target
    index GetTargetWeapon(AITarget)

    # Return primary weapon object
    weapon GetPrimaryWeapon()

    # Loop through the weapons to find the weapon with the longest range that is not manual fire
    float GetMaxWeaponRange()

    # Check if the target is within any weapon range
    bool IsWithinAttackRange(AITarget)
    bool IsWithinAttackRange(weapon, AITarget)
    bool IsWithinAttackRangePos(position)
    bool IsWithinAttackRangePos(weapon, position)

    # Check if the target is too close to our weapons
    bool IsTooClose(AITarget)

    # Check if the target is exempt from being attacked
    bool IsTargetExempt(entity)

    # Check if the attack has a slaved weapon that currently has a target
    AITarget HasSlavedTarget()

    # Reset reporting state
    ResetReportingState()

    # Force to engage enemy target
    ForceEngage(entity)
    --]]
}